package org.sonatype.mavenbook.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.sonatype.mavenbook.weather.WeatherService;

public class WeatherServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1464597163619987957L;

	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		//super.doGet(req, resp);
		String zip=req.getParameter("zip");
		WeatherService weatherServcie=new WeatherService();
		
		PrintWriter out=resp.getWriter();
		try {
			out.println(weatherServcie.retrieveForecast(zip));
		} catch (Exception e) {
			out.println("Error Retrieving Forecast"+e.getMessage());
		}
		out.flush();
		out.close();
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req,resp);
	}
	
}
